package com.example.testhilt.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.ViewModelProvider
import com.example.testhilt.R
import com.example.testhilt.module.MyViewModel
import com.example.testhilt.module.Truck
import dagger.hilt.android.AndroidEntryPoint
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import javax.inject.Inject

/**
 *
 * Hilt 使用
 *
 * https://mp.weixin.qq.com/s/OEX1d2cU1zGG5BBM-nANBg
 *
 * Jetpack新成员，App Startup一篇就懂
 * 
 * https://mp.weixin.qq.com/s/rverE0OGRnncB5-K-_Wesg
 */

@AndroidEntryPoint
class MainActivity : AppCompatActivity() {

    @Inject
    lateinit var okHttpClient: OkHttpClient

    // 第三方类的依赖注入
    @Inject
    lateinit var retrofit: Retrofit// 由 NetworkModule 里的 provideRetrofit 函数提供


    @Inject
    lateinit var truck: Truck;

    @Inject
//    lateinit var viewModel: MyViewModel// ViewModel的依赖注入


//    lateinit var truck: Truck;//  lateinit property truck has not been initialized

//     val truck: Truck? = null;

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        truck.deliver()// 没有使用  @Inject 抱错  lateinit property truck has not been initialized

//        truck?.deliver()

        val viewModel : MyViewModel by lazy { ViewModelProvider(this).get(MyViewModel::class.java) }

    }
}